package cn.tuling.org.controller;

import cn.tuling.basic.util.PageList;
import cn.tuling.org.domain.Photo;
import cn.tuling.org.query.PhotoQuery;
import cn.tuling.org.service.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/photo")
public class PhotoController {
    @Autowired
    private PhotoService photoService;
    @PostMapping
    public void addOrUpdate(@RequestBody Photo photo) {
        if (photo.getId() == null) {
            photoService.addPhoto(photo);
        } else {
            photoService.updatePhoo(photo);
        }

    }
    @DeleteMapping("/{id}")
    public void dele(@PathVariable("id") Long id) {
        photoService.delePhotoById(id);
    }
   @PutMapping
   public PageList<Photo> finaAllPhoto(@RequestBody PhotoQuery photoQuery) {
       return photoService.findPagingPhoto(photoQuery);
   }

}
